﻿using MvvmValidation;

namespace Budget.Silver.OutcomeServiceReference
{
    public partial class ProductData
    {
        public string ValidatableName
        {
            get { return Name; }
            set
            {
                if (!Name.Equals(value))
                {
                    if (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value))
                    {
                        throw new ValidationException("Имя не может быть пустым!");
                    }
                    Name = value;
                    RaisePropertyChanged("ValidatableName");
                }
            }
        }

        public override bool Equals(object obj)
        {
            var product = obj as ProductData;

            if (product != null)
            {
                return string.Equals(Name, product.Name);
            }

            return false;
        }

        public override int GetHashCode()
        {
            return (Name != null ? Name.GetHashCode() : 0);
        }

        public override string ToString()
        {
            return Name;
        }
    }
}